<template>
  <div class="spu_wrap">
    <BreadCrumb crumb="spu管理"></BreadCrumb>
    <div class="top_bar">
      <el-button type="primary" class="pull-right">
        <router-link to="/home/spuadd">新增spu</router-link>
      </el-button>
    </div>
    <SpuTable :spus="aSpuList" @fnResetTable="fnGetData"></SpuTable>
    <!-- <el-pagination
      background
      layout="prev, pager, next"
      :page-count="pages"
      :current-page="page"
      style="text-align:center;margin-top:10px"
      @current-change="fnGetPage"
      >
    </el-pagination> -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :current-page="page"
      :page-size="pagesize"
      style="text-align: center; margin-top: 10px"
      @current-change="fnGetPage"
    >
    </el-pagination>
  </div>
</template>

<script>
import BreadCrumb from "@/components/widget/BreadCrumb";
import SpuTable from "@/components/widget/SpuTable";

import cons from "@/components/constant";

export default {
  name: "Spu",
  data() {
    return {
      // page: 1,
      // pages: 4,
      // pagesize: 10,
      page: 1,
      pagesize: 4,
      total: 0,

      aSpuList: [],
    };
  },
  components: {
    BreadCrumb,
    SpuTable,
  },
  mounted() {
    this.fnGetData(1);
  },
  methods: {
    fnGetData: function (num) {
      let token = localStorage.token;
      this.axios
        .get(cons.apis + "/goods/spuslist/", {
          headers: {
            Authorization: "JWT " + token,
          },
          responseType: "json",
          // params: {
          //   page: num,
          //   pagesize: this.pagesize,
          // },
           params: {
            page: num, // 第几页数据
            pagesize: this.pagesize, // 每页显示的条数
            keyword: this.keyword,
          },
        })
        .then((dat) => {
          console.log("获取所有spus数据的响应》》", dat);
          this.aSpuList = dat.data.results;
          // this.page = dat.data.page;
          // this.pages = dat.data.pages;
          this.total = dat.data.count;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // fnGetPage: function (dat) {
    //   this.page = dat;
    //   this.fnGetData(this.page);
    // },
     // 切换分页时触发的方法
     fnGetPage: function (dat) {
       console.log("dat>>", dat);
       this.page = dat;
       this.fnGetData(this.page);
     },
  },
};
</script>

<style scoped>
.top_bar {
  width: 95.2%;
  overflow: hidden;
  margin: 10px auto;
}
a {
  display: block;
  color: #fff;
  width: 90px;
  line-height: 42px;
  margin: -15px -20px;
}
</style>
